/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.tables;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author david
 */
@Embeddable
public class ClockedPeriodPK implements Serializable {

    // <editor-fold defaultstate="collapsed" desc="Property Change Support">
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    } // </editor-fold>

    @Basic(optional = false)
    @Column(name = "badge_id")
    private Integer badgeId;

    @Basic(optional = false)
    @Column(name = "clocked_in")
    @Temporal(TemporalType.TIMESTAMP)
    private Date clockedIn;

    public ClockedPeriodPK() {
    }

    public ClockedPeriodPK(Integer badgeId, Date clockedIn) {
        this.badgeId = badgeId;
        this.clockedIn = clockedIn;
    }

    public Integer getBadgeId() {
        return badgeId;
    }

    public void setBadgeId(Integer badgeId) {
        Integer oldBadgeId = this.badgeId;
        this.badgeId = badgeId;
        changeSupport.firePropertyChange("badgeId", oldBadgeId, badgeId);
    }

    public Date getClockedIn() {
        return clockedIn;
    }

    public void setClockedIn(Date clockedIn) {
        Date oldClockedIn = this.clockedIn;
        this.clockedIn = clockedIn;
        changeSupport.firePropertyChange("clockedIn", clockedIn, oldClockedIn);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) badgeId;
        hash += (clockedIn != null ? clockedIn.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ClockedPeriodPK)) {
            return false;
        }
        ClockedPeriodPK other = (ClockedPeriodPK) object;
        if (this.badgeId != other.badgeId) {
            return false;
        }
        if ((this.clockedIn == null && other.clockedIn != null) || (this.clockedIn != null && !this.clockedIn.equals(other.clockedIn))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "TimeRecording.tables.ClockedPeriodPK[badgeId=" + badgeId + ", clockedIn=" + clockedIn + "]";
    }

}
